<!DOCTYPE html>
<meta charset="utf-8" />

<link rel="stylesheet" href="ace_v1.3/assets/css/ui.jqgrid.css" />

<div class="search_panel">
	<form action="mpamng/agent/queryAgentDeployFee.do" method="post"
		onsubmit="return pageSearch(this);">
		<div style="display: block;" class="widget-body ">
			<div class="widget-main">
				<div class="rowt">
					<div class="col-sm-12">
						<div>

							<div class="search_elm" style="margin-left: 0px; width: 300px;">
								<label class="label_search">合作商名称:</label>
								<div class="search_input">
									<select rel="obj.options"
										location="mpamng/selectoption/agentName.do" name="agentName"
										id="search_agentName" data-placeholder="请选择合作商名称"
										style="width: 200px; vertical-align: middle;">
										<option value=''>----请选择----</option>
									</select>
								</div>
							</div>

							<div class="search_elm" style="margin-left: 0px">
								<label class="label_search">支付渠道:</label>
								<div class="search_input">
									<select rel="rows" location="mpcoop/coopManage/query.do"
										name="channel" id="channel" valName="cooporgNo"
										textName="coopname" data="{'start':0,'pageSize':100}"
										style="width: 120px; vertical-align: middle;">
										<option value="">---选择---</option>
									</select>
								</div>
							</div>

							<div class="search_elm">
								<label class="label_search">费率类型:</label>
								<div class="search_input">
									<select rel="obj.RATETYPE" location="local" name="rateType"
										id="search_rateType" data-placeholder="请选择状态"
										style="width: 120px; vertical-align: middle;">
										<option value=''>--请选择--</option>
									</select>
								</div>
							</div>


							<div class="search_elm">
								<button class="btn btn-small btn_search" type="submit"
									title="搜索">搜索</button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</form>
</div>
<div class="rowt">
	<div class="col-xs-12">
		<table id="grid-table"></table>
		<div id="grid-pager"></div>

		<div style="margin-top: 10px">
			<span id="auth_btn"> 
			<a auth="mpamng/agent/addView.do" class="btn btn-small btn-add" onclick="addDeployFee();">新增</a> 
			<a auth="mpamng/agent/editView.do" class="btn btn-small btn-update" onclick="editDeployFee();">修改</a>
			<a class="btn btn-small btn-delete" onclick="deleteDeployFee();">删除</a>
			</span> <span id="paging_bar" style="float: right"> </span>
		</div>

	</div>
</div>
<!-- /.row -->

<script type="text/javascript">
	var jqGrid;
	jQuery(function($) {
		var grid_selector = "#grid-table";
		var pager_selector = "#grid-pager";

		$(window).on(
				'resize.jqGrid',
				function() {
					$(grid_selector).jqGrid('setGridWidth',
							$(".page-content").width());
				})
		var parent_column = $(grid_selector).closest('[class*="col-"]');
		$(document).on(
				'settings.ace.jqGrid',
				function(ev, event_name, collapsed) {
					if (event_name === 'sidebar_collapsed'
							|| event_name === 'main_container_fixed') {
						setTimeout(function() {
							$(grid_selector).jqGrid('setGridWidth',
									parent_column.width());
						}, 0);
					}
				})
		jQuery(grid_selector).jqGrid(
				{
					url : "mpamng/agent/queryAgentDeployFee.do",
					datatype : "json",
					height : '100%',
					width : '100%',
					colNames : [ '合作商编号', '合作商名称', '渠道编号', '费率类型', 'T0交易费率(成本)%',
							'T1交易费率(成本)%', 'T0最小手续费(成本)分', 'T0封顶手续费(成本)分',
							'T1最小手续费(成本)分', 'T1封顶手续费(成本)分', 'T0交易费率%', 'T1交易费率%',
							'T0最小手续费分', 'T0封顶手续费分', 'T1最小手续费分', 'T1封顶手续费分' ],
					colModel : [ {
						name : 'agentId',
						index : 'agentId',
						width : '100px'
					}, {
						name : 'agentName',
						index : 'agentName',
						width : '120px'
					},{
						name : 'channel',
						index : 'channel',
						width : '120px'
					}, {
						name : 'rateType',
						index : 'rateType',
						width : '130px'
					}, {
						name : 'costRateT0',
						index : 'costRateT0',
						width : '120px'
					}, {
						name : 'costRateT1',
						index : 'costRateT1',
						width : '100px'
					}, {
						name : 'costMinFeeT0',
						index : 'costMinFeeT0',
						width : '120px'
					}, {
						name : 'costMaxFeeT0',
						index : 'costMaxFeeT0',
						width : '100px'
					}, {
						name : 'costMinFeeT1',
						index : 'costMinFeeT1',
						width : '100px'
					}, {
						name : 'costMaxFeeT1',
						index : 'costMaxFeeT1',
						width : '120px'
					}, {
						name : 'rateT0',
						index : 'rateT0',
						width : '130px'
					}, {
						name : 'rateT1',
						index : 'rateT1',
						width : '120px'
					}, {
						name : 'minFeeT0',
						index : 'minFeeT0',
						width : '100px'
					}, {
						name : 'maxFeeT0',
						index : 'maxFeeT0',
						width : '120px'
					}, {
						name : 'minFeeT1',
						index : 'minFeeT1',
						width : '100px'
					}, {
						name : 'maxFeeT1',
						index : 'maxFeeT1',
						width : '60px'
					}, ],
					viewrecords : true,
					rowNum : 10,
					rowList : [ 10, 20, 30 ],
					altRows : true,
					shrinkToFit : false,
					multiselect : true,//设置行可多选的 
					multiboxonly : true,//
					sortable : false,

					loadComplete : function() {
						var table = this;
						setTimeout(function() {
							//加载分页
							initPagingBar(grid_selector);
						}, 0);
					},
					beforeRequest : function() {//请求之前执行
						jqGrid = this;
					},
				});
		$(window).triggerHandler('resize.jqGrid');

		$(document).one('ajaxloadstart.page', function(e) {
			$(grid_selector).jqGrid('GridUnload');
			$('.ui-jqdialog').remove();
		});

	});

	//新增
	function addDeployFee() {
		openDialog({
			dialogId : 'dlg-DeployFeeAdd',
			title : '新增合作商费率',
			pageUrl : 'mpamng/agent/addView.do',
			width : '50%',
			height : '70%'
		});
	}

	//修改
	function editDeployFee() {
		/* debugger; */
		var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");

		if (rows.length == 0) {
			msg.alert("警告", "当前没有选择数据项！", "error");
			return;
		}
		if (rows.length > 1) {
			msg.alert("警告", "不能同时选择多项数据！", "warn");
			return;
		}
		var strAgentId = "";
		var strChannel = "";
		var strRateType = "";
		for (var i = 0; i < rows.length; i++) {
			strAgentId += $('#grid-table').jqGrid('getRowData', rows[i]).agentId
					+ ",";
			strChannel += $('#grid-table').jqGrid('getRowData', rows[i]).channel
					+ ",";
			strRateType += $('#grid-table').jqGrid('getRowData', rows[i]).rateType
					+ ",";
		}
		openDialog({
			dialogId : 'dlg-cooporgedit',
			title : '修改合作商费率',
			pageUrl : 'mpamng/agent/editView.do',
			dataUrl : 'mpamng/agentfee/query.do?agentId=' + strAgentId
					+ '&channel=' + strChannel + '&rateType=' + strRateType,
			width : '50%',
			height : '55%',
			dataParam : {

			},
			dataName : 'obj' //表单数据存储对象名称

		});
	}
	//删除
	function deleteDeployFee() {
		var rows = $('#grid-table').jqGrid("getGridParam", "selarrrow");
		if (rows.length == 0) {
			msg.alert("警告", "当前没有选择数据项！", "warn");
			return;
		}
		/* var ids = "";
		for (var i = 0; i < rows.length; i++) {
			ids += "'" + $('#grid-table').jqGrid('getRowData',rows[i]).cooporgNo+ "'" + ",";
			
		}
		ids = ids.substring(0, ids.lastIndexOf(",")); */

		var strAgentId = "";
		var strChannel = "";
		var strRateType = "";
		for (var i = 0; i < rows.length; i++) {
			strAgentId += $('#grid-table').jqGrid('getRowData', rows[i]).agentId
					+ ",";
			strChannel += $('#grid-table').jqGrid('getRowData', rows[i]).channel
					+ ",";
			strRateType += $('#grid-table').jqGrid('getRowData', rows[i]).rateType
					+ ",";
		}

		msg.confirm({
			title : '确认',
			position : 'center',
			msg : '您确定要删除选中的数据吗？',
			call : function(ok) {
				if (ok) {
					$.ajax({
						type : "post",
						url : 'mpamng/deployFee/delete.do?agentId='
								+ strAgentId + '&channel=' + strChannel
								+ '&rateType=' + strRateType,
						dataType : 'json',
						success : function(result) {
							if (result.rspcod != 200) {
								msg.alert("错误", result.rspmsg + " 错误代码："
										+ result.rspcod, 'error');
							} else {
								msg.alert("提示", result.rspmsg, 'correct');
								$("#grid-table").trigger("reloadGrid");
							}
						},
						error : function(XMLHttpRequest, textStatus) {
							msg.alert("错误", "错误代码：" + XMLHttpRequest.status
									+ ",错误描述：" + textStatus, 'error');
						}
					});

				}
			}
		});
	}
</script>
